#ifndef	WF_PIDCONTROL_GLOBALS
#define	WF_PIDCONTROL_GLOBALS
#include <includes.h>

#define RESET_TIMEOUT_MS    1200

uint64_t GetSysTickMS(void)
{
    uint64_t SysTickMS = SysTickCount*5;
    return SysTickMS;
}

bool RequestPIDStart(uint8_t ShareInOrderSta_x) 
{
    bool is_success = false;

    if(ShareInOrderSta_x!=ShareInOrderSta_PriMoverStop)
    {
        // 检查启动条件
        if((GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_x]) == PIDOrderSta_DEF_NONE) && 
        !GetFlagShareBufferDataContent(NULL, CfgOperaType_None, FlagShareBuffer_GenWorkingSta, GenWorkStaOrd_AlarmShutDown)) 
        {
            // 设置状态为请求启动
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_x],PIDOrderSta_DEF_PIDREQ,1);            
            is_success = true;
        }
    }
    else
    {
        // 检查启动条件
        if((GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_x]) == PIDOrderSta_DEF_NONE)) 
        {
            // 设置状态为请求启动
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_x],PIDOrderSta_DEF_PIDREQ,1);            
            is_success = true;
        }
    }

    return is_success;
}

/**
 * @brief 请求原动机启动/停止
 * 
 * @param SetFre 倍率1
 * @param SetTime 加速时间 s
 * @param type 
 * @param TimeOut 单位s
 * @param ShareInOrderSta_x pid设置标志位
 */
uint8_t PidReqPriMoverStartStop(uint16_t SetFre,float SetTime,PriMover_ENUM_Type type,float TimeOut,uint8_t ShareInOrderSta_x)
{
    bool is_success = DEF_FALSE;
    switch (type)
    {
    case PriMover_ENUM_Type_Start:
        if(RequestPIDStart(ShareInOrderSta_PriMoverStart))
        {
            PriMoverConfig.SetFre = SetFre;
            PriMoverConfig.SetTime = SetTime;
            PriMoverConfig.type = type;
            PriMoverConfig.TimeOut = TimeOut;
            is_success = DEF_TRUE;
        }     
        break;
    case PriMover_ENUM_Type_Stop:
        if(RequestPIDStart(ShareInOrderSta_PriMoverStop))
        {
            PriMoverConfig.SetFre = SetFre;
            PriMoverConfig.SetTime = SetTime;
            PriMoverConfig.type = type;
            PriMoverConfig.TimeOut = TimeOut;
            is_success = DEF_TRUE;
        }     
        break;
    }
    return is_success;     
}

/**
 * @brief 请求建压电机启动到低限位
 * 
 * @param TimeOut 单位s
 */
uint8_t PidReqBVolLimVal(float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_BVolLimVal))
    {
        BVolLimVal_st.TimeOut = TimeOut;
        is_success = DEF_TRUE;
    }   
    return is_success;
}
/**
 * @brief 请求建压电机启动到预设值
 * 
 * @param SetVal 
 * @param TimeOut 单位s
 */
uint8_t PidReqBVolSetVal(float SetVal,float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_BVolSetVal))
    {
        BVolSetVal_st.SetVal = SetVal;
        BVolSetVal_st.TimeOut = TimeOut;
        is_success = DEF_TRUE;
    }   
    return is_success;
}

/**
 * @brief 请求建压电机启动到指定时间
 * 
 * @param Action 
 * @param RunTime 单位s
 */
uint8_t PidReqBVolSetTime(MotorAction Action,float RunTime)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_BVolSetTime))
    {
        BVolSetTime_st.Action = Action;
        BVolSetTime_st.RunTime = RunTime;
        is_success = DEF_TRUE;
    } 
    return is_success;
}
/**
 * @brief 请求励磁分压电机启动到低限位
 * 
 * @param TimeOut 单位s
 */
uint8_t PidReqExcvLimVal(float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExcvLimVal))
    {
        ExcvLimVal_st.TimeOut = TimeOut; 
        is_success = DEF_TRUE;
    } 
    return is_success;
}
/**
 * @brief 请求励磁分压电机启动到预设值
 * 
 * @param SetVal 
 * @param TimeOut 单位s
 */
uint8_t PidReqExcvSetVal(float SetVal,float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExcvSetVal))
    {
        ExcvSetVal_st.SetVal = SetVal;
        ExcvSetVal_st.TimeOut = TimeOut;
        is_success = DEF_TRUE;
    }       
    return is_success;    
}
/**
 * @brief 请求励磁分压启动到指定时间
 * 
 * @param Action 
 * @param RunTime 单位s
 */
uint8_t PidReqExcvSetTime(MotorAction Action,float RunTime)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExcvSetTime))
    {
        ExcvSetTime_st.Action = Action;
        ExcvSetTime_st.RunTime = RunTime;
        is_success = DEF_TRUE;
    }       
    return is_success;   
}
/**
 * @brief 请求励磁分流电机启动到低限位
 * 
 * @param TimeOut 单位s
 */
uint8_t PidReqExciLimVal(float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExciLimVal))
    {
        ExciLimVal_st.TimeOut = TimeOut;
        is_success = DEF_TRUE;
    }     
    return is_success;     
}
/**
 * @brief 请求励磁分流电机启动到预设值
 * 
 * @param SetVal 
 * @param TimeOut 单位s
 */
uint8_t PidReqExciSetVal(float SetVal,float TimeOut)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExciSetVal))
    {
        ExciSetVal_st.SetVal = SetVal;
        ExciSetVal_st.TimeOut = TimeOut;
        is_success = DEF_TRUE;
    }       
    return is_success;         
}
/**
 * @brief 请求励磁分流启动到指定时间
 * 
 * @param Action 
 * @param RunTime 单位s
 */
uint8_t PidReqExciSetTime(MotorAction Action,float RunTime)
{
    bool is_success = DEF_FALSE;
    if(RequestPIDStart(ShareInOrderSta_ExciSetTime))
    {
        ExciSetTime_st.Action = Action;
        ExciSetTime_st.RunTime = RunTime;
        is_success = DEF_TRUE;
    }   
    return is_success;  
}


static float ComputeOutPut(float setpoint,float currentVal)
{
	float temKp=2.5;
	// 计算误差
	float error = setpoint - currentVal;
	// 计算PID输出
	float control_output = temKp * error;

	return control_output;
}
static uint8_t WorkFlowHandling_BVolLimVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    static uint32_t enter_state_tick = 0;
    static MotorLimVal_ST TemBVolLimVal_st;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        motorTurn(BUILDVOL_MOTOR,motorStop);
		WFAction |= WorkflowOutRequestBit_RelayOut;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        TemBVolLimVal_st = BVolLimVal_st;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - enter_state_tick > TemBVolLimVal_st.TimeOut * 1000)
        {
            // 产生超时警告
            ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_BVOL_Mac_Fail,BitOperaOpt_Set);
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        // 低限位成功
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_DI_BVOL_LLimit))
        {
            motorTurn(BUILDVOL_MOTOR,motorStop);
            WFAction |= WorkflowOutRequestBit_RelayOut;
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_SUCCESSBEF,1);
            break;
        }

        motorTurn(BUILDVOL_MOTOR,motorREV);
        WFAction |= WorkflowOutRequestBit_RelayOut;
        break;
    case PIDOrderSta_DEF_SUCCESSBEF:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolLimVal],PIDOrderSta_DEF_NONE,1);
        }
        break;
    }
    return WFAction;
}
static uint8_t WorkFlowHandling_BVolSetVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    static uint32_t enter_state_tick = 0;
    static MotorSetVal_ST TemBVolSetVal_st;
    float control_output;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        motorTurn(BUILDVOL_MOTOR,motorStop);
		WFAction |= WorkflowOutRequestBit_RelayOut;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        TemBVolSetVal_st = BVolSetVal_st;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - enter_state_tick > TemBVolSetVal_st.TimeOut * 1000)
        {
            // 产生超时警告
            ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_BVOL_Mac_Fail,BitOperaOpt_Set);
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        control_output = ComputeOutPut(TemBVolSetVal_st.SetVal,ACAD_RTGlobalData.BuildVoltData.BuildVoltAFT);
        if(fabsf(control_output)<0.5)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_SUCCESSBEF,1);
            motorTurn(BUILDVOL_MOTOR,motorStop);
            WFAction |= WorkflowOutRequestBit_RelayOut;
            break;
        }
        // 正转
        if(control_output>0)
        {
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_DI_BVOL_HLimit))
            {
                ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_BVOL_LLimit,BitOperaOpt_Set);
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_EMSTOP,1);
            }
            else
            {
                motorTurn(BUILDVOL_MOTOR,motorFOR);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }

        // 反转
        if(control_output<0)
        {
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_DI_BVOL_LLimit))
            {
                ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,RawAlarm_BVOL_LLimit,BitOperaOpt_Set);
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_EMSTOP,1);
            }
            else
            {
                motorTurn(BUILDVOL_MOTOR,motorFOR);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        break;  
    case PIDOrderSta_DEF_SUCCESSBEF:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetVal],PIDOrderSta_DEF_NONE,1);
        }
        break; 
    }

    return WFAction;
}

static uint8_t WorkFlowHandling_BVolSetTime(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    static uint32_t enter_state_tick = 0;
    static MotorSetTime_ST TemBVolSetTime_st;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        motorTurn(BUILDVOL_MOTOR,motorStop);
		WFAction |= WorkflowOutRequestBit_RelayOut;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        TemBVolSetTime_st = BVolSetTime_st;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - enter_state_tick > TemBVolSetTime_st.RunTime * 1000)
        {
            motorTurn(BUILDVOL_MOTOR,motorStop);
            WFAction |= WorkflowOutRequestBit_RelayOut;
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_SUCCESSBEF,1);
            break;
        }
        motorTurn(BUILDVOL_MOTOR,TemBVolSetTime_st.Action);
        WFAction |= WorkflowOutRequestBit_RelayOut;
        break;
    case PIDOrderSta_DEF_SUCCESSBEF:
        enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_BVolSetTime],PIDOrderSta_DEF_NONE,1);
        }
        break;
    }

    return WFAction;
}

/**
 * @brief 控制两个电机转动
 * 
 * @param Arg_st 
 * @return uint8_t 
 */
static uint8_t CommonHandling_BothMotorRun(BothMotorRunArg_ST *Arg_st)
{
    uint8_t WFAction = DEF_FALSE;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        motorTurn(Arg_st->motor1,motorStop);
        motorTurn(Arg_st->motor2,motorStop);
		WFAction |= WorkflowOutRequestBit_RelayOut;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        *Arg_st->enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - *Arg_st->enter_state_tick > Arg_st->TimeOut * 1000)
        {
            if(Arg_st->type==BothMotorSetArg_ENUM_Type_LLimt)
            {
                // 1.规定时间未达到限位
                ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_MAC_Fail,BitOperaOpt_Set);
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
            }
            else
            {   
                // 2.转动规定时间到
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESSBEF,1);
                motorTurn(Arg_st->motor1,motorStop);
                motorTurn(Arg_st->motor2,motorStop);
            }
            break;
        }

        if(Arg_st->Action==motorFOR)
        {
            if(Arg_st->type==BothMotorSetArg_ENUM_Type_LLimt)
                break;
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI1_HLimit))
            {
                if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI2_HLimit))
                {
                    FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESSBEF,1);
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorStop);
                }
                else
                {
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorFOR);
                }
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
            else
            {
                motorTurn(Arg_st->motor1,motorFOR);
                motorTurn(Arg_st->motor2,motorStop);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        else if(Arg_st->Action==motorREV)
        {
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI2_LLimit))
            {
                if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI1_LLimit))
                {
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorStop);
                    FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESSBEF,1);
                }
                else
                {
                    motorTurn(Arg_st->motor2,motorStop);
                    motorTurn(Arg_st->motor1,motorREV);
                }
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
            else
            {
                motorTurn(Arg_st->motor2,motorREV);
                motorTurn(Arg_st->motor1,motorStop);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        else
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
        }
        break;
    case PIDOrderSta_DEF_SUCCESSBEF:
        *Arg_st->enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - *Arg_st->enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        }
        break;
    }
    return WFAction;
}

/**
 * @brief 控制两个电机转动到指定值
 * 
 * @param Arg_st 
 * @return uint8_t 
 */
static uint8_t CommonHandling_BothSetVal(BothMotorSetValArg_ST *Arg_st)
{
    uint8_t WFAction = DEF_FALSE;
    float control_output;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        motorTurn(Arg_st->motor1,motorStop);
        motorTurn(Arg_st->motor2,motorStop);
		WFAction |= WorkflowOutRequestBit_RelayOut;
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        *Arg_st->enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - *Arg_st->enter_state_tick > Arg_st->TimeOut * 1000)
        {
            ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_MAC_Fail,BitOperaOpt_Set);
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        control_output = ComputeOutPut(Arg_st->SetVal,*Arg_st->ComputeSource);
        if(fabsf(control_output)<0.5)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESSBEF,1);
            motorTurn(Arg_st->motor1,motorStop);
            motorTurn(Arg_st->motor2,motorStop);
            WFAction |= WorkflowOutRequestBit_RelayOut;
            break;
        }

        if(control_output>0)
        {
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI1_HLimit))
            {
                if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI2_HLimit))
                {
                    ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_MAC_HLimit,BitOperaOpt_Set);
                    FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->RawAlarm_MAC_HLimit],PIDOrderSta_DEF_NONE,1);
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorStop);
                }
                else
                {
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorFOR);
                }
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
            else
            {
                motorTurn(Arg_st->motor1,motorFOR);
                motorTurn(Arg_st->motor2,motorStop);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        if(control_output<0)
        {
            if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI2_LLimit))
            {
                if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_DI1_LLimit))
                {
                    ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,Arg_st->RawAlarm_MAC_HLimit,BitOperaOpt_Set);
                    FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->RawAlarm_MAC_LLimit],PIDOrderSta_DEF_NONE,1);
                    motorTurn(Arg_st->motor1,motorStop);
                    motorTurn(Arg_st->motor2,motorStop);
                }
                else
                {
                    motorTurn(Arg_st->motor2,motorStop);
                    motorTurn(Arg_st->motor1,motorREV);
                }
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
            else
            {
                motorTurn(Arg_st->motor2,motorREV);
                motorTurn(Arg_st->motor1,motorStop);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        else
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
        }
        break;
    case PIDOrderSta_DEF_SUCCESSBEF:
        *Arg_st->enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - *Arg_st->enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        }
        break;
    }
    return WFAction;
}

static uint8_t WorkFlowHandling_ExcvLimVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorRunArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = BothMotorSetArg_ENUM_Type_LLimt;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExcvLimVal;
    Arg_st.motor1=EXCV_MOTOR;
    Arg_st.motor2=EXCV2_MOTOR;
    Arg_st.Action=motorREV;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExcvLimVal_st.TimeOut;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCV_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCV2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCV_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCV2_HLimit;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_EXCV_MAC_Fail;
    WFAction |= CommonHandling_BothMotorRun(&Arg_st);
    return WFAction;
}
static uint8_t WorkFlowHandling_ExcvSetVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorSetValArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.SetVal = ExcvSetVal_st.SetVal;
    Arg_st.ComputeSource = &ACAD_RTGlobalData.GenExcitationData.ExcitationVolt;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExcvSetVal;
    Arg_st.motor1=EXCV_MOTOR;
    Arg_st.motor2=EXCV2_MOTOR;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExcvSetVal_st.TimeOut;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCV_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCV2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCV_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCV2_HLimit;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_EXCV_MAC_Fail;
    Arg_st.RawAlarm_MAC_LLimit=RawAlarm_EXCV_MOT_LLimit;
    Arg_st.RawAlarm_MAC_HLimit=RawAlarm_EXCV_MOT_HLimit;
    WFAction |= CommonHandling_BothSetVal(&Arg_st);
    return WFAction;
}

static uint8_t WorkFlowHandling_ExcvSetTime(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorRunArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = BothMotorSetArg_ENUM_Type_RTime;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExcvSetTime;
    Arg_st.motor1=EXCV_MOTOR;
    Arg_st.motor2=EXCV2_MOTOR;
    Arg_st.Action=ExcvSetTime_st.Action;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExcvSetTime_st.RunTime;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCV_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCV2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCV_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCV2_HLimit;
    // Arg_st.RawAlarm_MAC_Fail=RawAlarm_EXCV_MAC_Fail; // no need
    WFAction |= CommonHandling_BothMotorRun(&Arg_st);
    return WFAction;
}


static uint8_t WorkFlowHandling_EvciLimVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorRunArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = BothMotorSetArg_ENUM_Type_LLimt;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExciLimVal;
    Arg_st.motor1=EXCI_MOTOR;
    Arg_st.motor2=EXCI2_MOTOR;
    Arg_st.Action=motorREV;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExciLimVal_st.TimeOut;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCI_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCI2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCI_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCI2_HLimit;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_EXCI_MAC_Fail;
    WFAction |= CommonHandling_BothMotorRun(&Arg_st);
    return WFAction;
}
static uint8_t WorkFlowHandling_EvciSetVal(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorSetValArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.SetVal = ExciSetVal_st.SetVal;
    Arg_st.ComputeSource = &ACAD_RTGlobalData.GenExcitationData.ExcitationCurr;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExciSetVal;
    Arg_st.motor1=EXCI_MOTOR;
    Arg_st.motor2=EXCI2_MOTOR;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExciSetVal_st.TimeOut;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCI_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCI2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCI_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCI2_HLimit;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_EXCI_MAC_Fail;
    Arg_st.RawAlarm_MAC_LLimit=RawAlarm_EXCI_MOT_LLimit;
    Arg_st.RawAlarm_MAC_HLimit=RawAlarm_EXCI_MOT_HLimit;
    WFAction |= CommonHandling_BothSetVal(&Arg_st);
    return WFAction;
}
static uint8_t WorkFlowHandling_EvciSetTime(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    BothMotorRunArg_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = BothMotorSetArg_ENUM_Type_RTime;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_ExciSetTime;
    Arg_st.motor1=EXCI_MOTOR;
    Arg_st.motor2=EXCI2_MOTOR;
    Arg_st.Action=ExciSetTime_st.Action;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=ExciSetTime_st.RunTime;
    Arg_st.RawAlarm_DI1_LLimit=RawAlarm_DI_EXCI_LLimit;
    Arg_st.RawAlarm_DI2_LLimit=RawAlarm_DI_EXCI2_LLimit;
    Arg_st.RawAlarm_DI1_HLimit=RawAlarm_DI_EXCI_HLimit;
    Arg_st.RawAlarm_DI2_HLimit=RawAlarm_DI_EXCI2_HLimit;
    WFAction |= CommonHandling_BothMotorRun(&Arg_st);
    return WFAction;
}

static uint8_t CommonHandling_PriMover(PriMover_ST *Arg_st)
{
    uint8_t WFAction = DEF_FALSE;
    static PriMover_ST TemArg_st;

    switch (GetShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x]))
    {
    case PIDOrderSta_DEF_EMSTOP:
        if(TemArg_st.type==PriMover_ENUM_Type_Start)
            PMotor_WorkModeSwitch(StopType,0,10);
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        break;
    case PIDOrderSta_DEF_NONE:
        break;
    case PIDOrderSta_DEF_PIDREQ:
        TemArg_st = *Arg_st;
        *TemArg_st.enter_state_tick  = (uint32_t)GetSysTickMS();
        if(TemArg_st.type==PriMover_ENUM_Type_Start)
        {
            if(pMotorStatus_st.ruing)
                PMotor_SetFrequenceEx((uint16_t)(TemArg_st.SetFre*100*share_parameterCfgData_st.baseData_st.PriFreCalibCoefficient));
            else
            {
                PMotor_WorkModeSwitch(StartType,(uint16_t)(TemArg_st.SetFre*100*share_parameterCfgData_st.baseData_st.PriFreCalibCoefficient),TemArg_st.SetTime*10);
                // 打开励磁电源
                ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,ShareBuffer_Outputs,RelayOutput_AUX_OUT1,BitOperaOpt_Set);
                WFAction |= WorkflowOutRequestBit_RelayOut;
            }
        }
        else
        {
            PMotor_WorkModeSwitch(StopType,(uint16_t)(TemArg_st.SetFre*100*share_parameterCfgData_st.baseData_st.PriFreCalibCoefficient),TemArg_st.SetTime*10);
        }
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_RUNNING,1);
        break;
    case PIDOrderSta_DEF_RUNNING:
        if(GetFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_GenWorkingSta,GenWorkStaOrd_AlarmShutDown))
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_EMSTOP,1);
            break;
        }
        if((uint32_t)GetSysTickMS() - *TemArg_st.enter_state_tick > TemArg_st.TimeOut * 1000)
        {
            // 产生超时警告
            ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,FlagShareBuffer_RawAlarm,TemArg_st.RawAlarm_MAC_Fail,BitOperaOpt_Set);
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
            break;
        }
        if(TemArg_st.type==PriMover_ENUM_Type_Start)
        {
            if(pMotorStatus_st.curFreq>=TemArg_st.SetFre-2)
            {
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESSBEF,1);
            }
        }
        else
        {
           if(pMotorStatus_st.stop || pMotorStatus_st.curFreq<=5)
            {
                // 关闭励磁电源
                ModifyFlagShareBufferDataContent(NULL,CfgOperaType_None,ShareBuffer_Outputs,RelayOutput_AUX_OUT1,BitOperaOpt_Clr);
                WFAction |= WorkflowOutRequestBit_RelayOut;
                FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[ShareInOrderSta_PriMoverStop],PIDOrderSta_DEF_SUCCESSBEF,1);
            }
        }
        break;
    case PIDOrderSta_DEF_SUCCESSBEF:
        *TemArg_st.enter_state_tick  = (uint32_t)GetSysTickMS();
        FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_SUCCESS,1);
        break;
    case PIDOrderSta_DEF_SUCCESS:
        if((uint32_t)GetSysTickMS() - *TemArg_st.enter_state_tick > RESET_TIMEOUT_MS)
        {
            FillShareBufferDataContent(App_Sem_WORKFLOW, CfgOperaType_OSSem, &ShareBuffer_SharePIDOrderSta[Arg_st->ShareInOrderSta_x],PIDOrderSta_DEF_NONE,1);
        }
        break;
    }
    return WFAction;
}
static uint8_t WorkFlowHandling_PriMoverStart(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    PriMover_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = PriMover_ENUM_Type_Start;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_PriMoverStart;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=PriMoverConfig.TimeOut;
    Arg_st.SetTime=PriMoverConfig.SetTime;
    Arg_st.SetFre=PriMoverConfig.SetFre;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_StartPriMotor_Fail;
    WFAction |= CommonHandling_PriMover(&Arg_st);
    return WFAction;
}
static uint8_t WorkFlowHandling_PriMoverStop(uint8_t TempWorkflow)
{
    uint8_t WFAction = DEF_FALSE;
    PriMover_ST Arg_st;
    static uint32_t enter_state_tick = 0;
    Arg_st.type = PriMover_ENUM_Type_Stop;
    Arg_st.ShareInOrderSta_x=ShareInOrderSta_PriMoverStop;
    Arg_st.enter_state_tick=&enter_state_tick;
    Arg_st.TimeOut=PriMoverConfig.TimeOut;
    Arg_st.SetTime=PriMoverConfig.SetTime;
    Arg_st.SetFre=PriMoverConfig.SetFre;
    Arg_st.RawAlarm_MAC_Fail=RawAlarm_StopPriMotor_Fail;
    WFAction |= CommonHandling_PriMover(&Arg_st);
    return WFAction;
}
/* 工作流程 */
typedef uint8_t (*WorkFlowHandlingType)(uint8_t TempWorkflow);
static const WorkFlowHandlingType WorkFlowHandlingTable[ShareInOrderSta_TOTNum] = {
    (WorkFlowHandlingType)WorkFlowHandling_BVolLimVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_BVolSetVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_BVolSetTime     ,
    (WorkFlowHandlingType)WorkFlowHandling_ExcvLimVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_ExcvSetVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_ExcvSetTime     ,
    (WorkFlowHandlingType)WorkFlowHandling_EvciLimVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_EvciSetVal      ,
    (WorkFlowHandlingType)WorkFlowHandling_EvciSetTime     ,
    (WorkFlowHandlingType)WorkFlowHandling_PriMoverStart   ,
    (WorkFlowHandlingType)WorkFlowHandling_PriMoverStop    ,
};

uint8_t PIDControlRequestWorkLayerHandle(uint8_t TempWorkflow, uint8_t *ActInform)
{
	uint8_t WFAction = DEF_FALSE;
	/* *********** 建压 ********** */
    for(uint8_t ShareInOrderSta_I=0;ShareInOrderSta_I<ShareInOrderSta_TOTNum;ShareInOrderSta_I++)
        WFAction |=(*WorkFlowHandlingTable[ShareInOrderSta_I])(TempWorkflow);

	return WFAction;
}
#endif